package 力扣日常刷题.木23一月.第09天309;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/3/9
 * @description
 */
public class Demo27顺子 {

    public static void main(String[] args) {
        isStraight(new int[]{0,0,8,5,4});
    }

    public static boolean isStraight(int[] nums) {
        Arrays.sort(nums);
        int zero = 0;

        for (int i = 0; i < 5; i++) {
            if (nums[i] == 0) {
                zero++;
                continue;
            } else {
                if(i != 0 && nums[i - 1] == nums[i]) return false;
                zero = i == 0 || nums[i - 1] == 0 ? zero : zero - nums[i] + nums[i - 1] +1;
                if (zero < 0) return false;
            }
        }

        return true;


    }

}
